﻿package com.victim.snake.graphics.roomClass{
	import flash.display.Sprite;
	import flash.display.Graphics;
    import flash.display.Bitmap;
    import com.victim.snake.snake.SnakeStyle;
    import flash.events.MouseEvent;
    import com.victim.snake.user.User;
    import flash.utils.ByteArray;
    import com.victim.snake.user.ProcessMsg;
	


	//蛇样式显示框
	public class ShowSnakeStyleSprite extends Sprite{
		private var snakeStyle:SnakeStyle=null;
		
		public function ShowSnakeStyleSprite(snakeStyle:SnakeStyle=null):void{			
			if(snakeStyle!=null){
				setSnakeStyle(snakeStyle);
			}
			this.addEventListener(MouseEvent.CLICK,selectSnakeStyleEvent);
		}
		
		//设置并显示snakeStyle
		public function setSnakeStyle(snakeStyle:SnakeStyle):void{
			this.snakeStyle=snakeStyle;
			var bitMap:Bitmap=new Bitmap(this.snakeStyle.smallThumbnailsImage.bitmapData);
			this.addChild(bitMap);
		}
		
		public function getSnakeStyle():SnakeStyle{
			return this.snakeStyle;
		}
		
		
		
		//玩家选择蛇样式事件
		public function selectSnakeStyleEvent(e:MouseEvent):void{
			//如果非玩家当前样式，择向服务器发送选择新样式请求
			if(this.getSnakeStyle()!=null && User.getPlayer().getSnakeStyle()!=this.getSnakeStyle().getName()){
				ProcessMsg.socketSend(ProcessMsg.generateUTF8Msg(20,this.getSnakeStyle().getName()));
			}
		}

	}
}